<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 第一题
        const obj = {
            id: 9,
            uname: 'zs',
            age: 18,
            hobbit: ['抽烟', '喝酒', '烫头'],
            obj2: {
                id: 10,
                uname: "ls",
                age: 28,
                hobbit: ['吃饭', '睡觉', '敲代码']
            }
        }
        let { id, uname, age, hobbit, hobbit: [a, b, c], obj2, obj2: { id: id1, uname: uname1, age: age1, hobbit: hobbit1, hobbit: [d, e, f] } } = obj
        console.log(id, uname, age);
        console.log(hobbit, a, b, c);
        console.log(obj2, id1, uname1, age1);
        console.log(hobbit1, d, e, f);

        // 第二题
        const createCounter = () => {
            let i = 0
            const counter = () => {
                i++
                return i
            }
            return counter
        }
        const counter = createCounter();
        console.log(counter()); // 1
        console.log(counter()); // 2
        console.log(counter());

        // 第三题
        const makeAdder = a => {
            const addFive = b => {
                return a + b
            }
            return addFive
        }
        const addFive = makeAdder(5);
        console.log(addFive(10)); // 15
        console.log(addFive(20));

        // 第四题
        const makeMultiplier = a => {
            const multiplyByThree = b => {
                return a * b
            }
            return multiplyByThree
        }

        const multiplyByThree = makeMultiplier(3);
        console.log(multiplyByThree(5)); // 15
        console.log(multiplyByThree(10));

        // 第五题
        const createIncrementor = (a) => {
            const incrementor = () => {
                a++
                return a
            }
            return incrementor
        }
        const incrementor = createIncrementor(10);
        console.log(incrementor()); // 11
        console.log(incrementor()); // 12
        console.log(incrementor()); // 13

        // 第六题
        const createCounter1=(a)=>{
            const counter1=(b)=>{
                if(b===undefined){
                    a++
                    return a
                }
                    b++
                    a=b
                    return b
            }
            return counter1
        }
        const counter1 = createCounter1(5);
        console.log(counter1()); // 6
        console.log(counter1()); // 7
        console.log(counter1()); // 8
        console.log(counter1(10)); // 11
        console.log(counter1());
        console.log(counter1(16));
        console.log(counter1());

    </script>
</body>

</html>